#!/bin/sh
# Environment
# _SVN_ROOT	the base subversion repository to use
# _SVN_BRANCH	default branch to checkout, defaults to 'trunk'\

DEV_SVN_BRANCH="${_SVN_BRANCH:-trunk}"
DEV_SVN_ROOT="${_SVN_ROOT:-$_SVN_REPOSITORY}"
DEV_SVN_ROOT="${DEV_SVN_ROOT%/}"
DEV_SVN_REPOSITORY="${DEV_SVN_ROOT}/${DEV_SVN_BRANCH}"

checkout () {
  local repository
echo $#
  case $# in
    0) repository=$DEV_SVN_REPOSITORY; dir=$DEV_SVN_BRANCH;;
    1) repository=$DEV_SVN_ROOT/$1; dir=$1;;
    2) repository=$1/$2; dir=$2;;
    3) repository=$1/$2; dir=$3;;
    *) echo no repository; return;;
  esac
  svn checkout $repository $dir
}

export -f checkout
export DEV_SVN_BRANCH DEV_SVN_ROOT DEV_SVN_REPOSITORY

$DEV_CLEAN && unset _SVN_REPOSITORY _SVN_BRANCH
